package com.qk.mangement.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.business.AddBusinessDTO;
import com.qk.domain.business.QueryPageBusinessDTO;
import com.qk.dto.business.QueryPoolBusinessDTO;
import com.qk.dto.business.TrackBusinessDTO;
import com.qk.mangement.service.BusinessService;
import com.qk.vo.business.QueryBusinessVO;
import com.qk.vo.business.QueryPageBusinessVO;
import com.qk.vo.business.QueryPoolBusinessVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Date:2025/10/15
 * Author:zxc
 * Description
 */
@Slf4j
@RestController
@RequestMapping("/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    @GetMapping
    public Result queryListByPage(QueryPageBusinessDTO queryPageBusinessDTO) {
        log.info("商机分页查询参数：{}", queryPageBusinessDTO);
        PageResult<QueryPageBusinessVO> queryListByPageVO = businessService.queryListByPage(queryPageBusinessDTO);
        return Result.success(queryListByPageVO);
    }

    @PostMapping
    public Result addBusiness(@RequestBody AddBusinessDTO addBusinessDTO){
        log.info("添加商机参数：{}", addBusinessDTO);
        businessService.addBusiness(addBusinessDTO);
        return Result.success();
    }


    @PutMapping("/assign/{businessId}/{userId}")
    public Result assignBusiness(@PathVariable Integer businessId, @PathVariable Integer userId){
        log.info("分配商机参数,businessId：{},userId:{}", businessId, userId);
        businessService.assignBusiness(businessId,userId);
        return Result.success();
    }


    @PutMapping("/back/{id}")
    public Result backBusiness(@PathVariable Integer id){
        log.info("踢回公海商机参数,id：{}", id);
        businessService.backBusiness(id);
        return Result.success();
    }


    @PostMapping("/toCustomer/{id}")
    public Result businessToCustomer(@PathVariable Integer id){
        log.info("商机转化为客户参数,id：{}", id);
        businessService.businessToCustomer(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
        log.info("查询商机参数,id：{}", id);
        QueryBusinessVO queryPageBusinessVo = businessService.queryById(id);
        return Result.success(queryPageBusinessVo);
    }

    @PutMapping
    public Result trackBusiness(@RequestBody TrackBusinessDTO trackBusinessDTO){
        log.info("商机跟进参数,business：{}", trackBusinessDTO);
        businessService.trackBusiness(trackBusinessDTO);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result queryBusinessPool(QueryPoolBusinessDTO queryPoolBusinessDTO){
        log.info("商机公海查询参数：{}", queryPoolBusinessDTO);
        PageResult<QueryPoolBusinessVO> queryListByPageVO = businessService.queryBusinessPool(queryPoolBusinessDTO);
        return Result.success(queryListByPageVO);
    }
}
